package com.yhans.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.yhans.constant.MessageConstant;
import com.yhans.entity.Result;
import com.yhans.pojo.Setmeal;
import com.yhans.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")

public class SetmealController {

    @Reference
    private SetmealService setmealService;
    //向前台(体检预约)展示所有的套餐信息
    @RequestMapping("/findAll")
    public Result findAll(){

        List<Setmeal> setmealList = setmealService.findAll();
        if (setmealList != null && setmealList.size() != 0) {
            return new Result(true, MessageConstant.GET_SETMEAL_LIST_SUCCESS, setmealList);
        }else {
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    //根据id查询套餐信息(向前台展示 套餐信息,检查组信息, 检查项信息(关联查询))
    @RequestMapping("/findById")
    public Result findById(Integer id){

        try {
            Setmeal setmealById = setmealService.findById(id);

           //Setmeal setmealById = setmealService.testFindById(id);
            return new Result(true,MessageConstant.QUERY_SETMEAL_SUCCESS,setmealById);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
